package com.desmart.ht;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.desmart.ht.utils.ToastUtils;
import com.unnamed.b.atv.model.TreeNode;

/**
 * Created by Bogdan Melnychuk on 2/12/15.
 */
public class IconTreeItemHolder extends TreeNode.BaseNodeViewHolder<IconTreeItemHolder.IconTreeItem> {
    private ImageView image;

    public IconTreeItemHolder(Context context) {
        super(context);
    }

    @Override
    public View createNodeView(final TreeNode node, IconTreeItem value) {
        final LayoutInflater inflater = LayoutInflater.from(context);
        final View view = inflater.inflate(R.layout.layout_icon_node, null, false);
        TextView tvName = view.findViewById(R.id.tv_name);
        image = view.findViewById(R.id.image);
        if (value.show){
            image.setVisibility(View.VISIBLE);
        }else{
            image.setVisibility(View.INVISIBLE);
        }

        LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) image.getLayoutParams();
        lp.leftMargin = value.type * 50;
        image.setLayoutParams(lp);

        tvName.setText(value.text);

        if (!value.show){
            tvName.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    ScheduleDetailActivity.start(context,ScheduleDetailActivity.type_watch);
                }
            });
        }

        return view;
    }

    @Override
    public void toggle(boolean active) {
        image.setImageResource(active ? R.drawable.ic_eye_open : R.drawable.ic_eye_close);
    }

    public static class IconTreeItem {
        public int icon;
        public String text;
        public boolean show = true;
        public int type = 1;

        public IconTreeItem(String text) {
            this.text = text;
        }

        public IconTreeItem(String text,int type,boolean show) {
            this.text = text;
            this.type = type;
            this.show = show;
        }

    }
}
